home *** CD-ROM | disk | FTP | other *** search
/ BBS in a Box 3 / BBS in a box - Trilogy III.iso / Files / Bus / C / Commander Demo / Commander Demo.rsrc / TEXT_5009_ADD TO SET.txt < prev    next >
Encoding:
Text File  |  1993-09-07  |  2.5 KB  |  50 lines

  1. ADD¬†TO¬†SET ({file}; set)
  2.                                                                                     Pg 41-8
  3.   
  4. file        File            File from which to add current record
  5. set          String        Name of the set to which to add the record
  6.  
  7.  
  8. ADD TO SET adds the current record of file to set. The set must already exist; if it does not, an error occurs. If a current record does not exist for file, ADD TO SET has no effect.
  9.  
  10.  
  11. The example below deletes duplicate records from a file. The file contains information about people. A ¬†For loop moves through all the records, comparing the current record to the previous record. If the first name and the last name are the same, then the record is added to a set. At the end of the loop, the set is made the current selection and the current selection is deleted:
  12.  
  13. CREATE EMPTY SET ([People]; "Duplicates") 
  14.                                            `  Create an empty set for duplicate records 
  15. ALL RECORDS ([People])   ` Select all records Sort the records by 
  16.                                            ` ZIP, address, and name so that the 
  17.                                            ` duplicates will be next to each other 
  18. SORT SELECTION ([People]; [Addresses]ZIP; >; [Addresses]Address; >; [Addresses]Name; >) 
  19.                                               ` Initialize variables that hold the 
  20. $Name := [People]Name           ` fields from the previous record 
  21. $Address := [People]Address 
  22. $ZIP := [People]ZIP 
  23. NEXT RECORD ([People])   ` Go to second record to compare to first 
  24. `
  25. For ($i; 2; Records in file ([People])) ` Loop thru records, start at 2 
  26.         ` If the name, address, and ZIP are the same as the previous 
  27.          ` record then it is a duplicate record.
  28.    If (([People]Name = $Name) & ([People]Address = $Address) & ([People]ZIP = $ZIP)) 
  29.       ADD TO SET ([People]; "Duplicates')
  30.             ` Add current record (the duplicate) to set
  31.     Else
  32.                                           ` Save this record's name, address, and ZIP 
  33.       $Name := [People]Name  ` for comparison with the next record 
  34.       $Address := [People]Address 
  35.       $ZIP := [People]ZIP
  36.    End if
  37.    NEXT RECORD ([People])   ` Move to the next record
  38. End for
  39. USE SET ("Duplicates")             ` Use duplicate records that were found
  40. DELETE SELECTION ([People]) ` Delete the duplicate records
  41. CLEAR SET ("Duplicates")         ` Remove the set from memory
  42.  
  43.  
  44.  
  45. See also: ALL¬†RECORDS, CLEAR¬†SET, CREATE¬†SET, 
  46.               CREATE¬†EMPTY¬†SET, NEXT¬†RECORD, 
  47.               Records¬†in¬†selection, SORT¬†SELECTION
  48.  
  49.  
  50.